package com.example.communicationfragment.sharedviewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class ItemViewModel extends ViewModel {

    private MutableLiveData<String> data = new MutableLiveData<>();

    // 让外部只能读取 LiveData，不能修改
    public LiveData<String> getData() {
        return data;
    }

    // 只有 ViewModel 内部可以修改数据
    public void setData(String newData) {
        data.setValue(newData);  // 更新数据
    }
}
